home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / ld / testsuite / ld-shared / sh1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-04  |  2.4 KB  |  148 lines

  1. /* This is part of the shared library ld test.  This file becomes part
  2.    of a shared library.  */
  3.  
  4. /* This variable is supplied by the main program.  */
  5. #ifndef XCOFF_TEST
  6. extern int mainvar;
  7. #endif
  8.  
  9. /* This variable is defined in the shared library, and overridden by
  10.    the main program.  */
  11. #ifndef XCOFF_TEST
  12. int overriddenvar = -1;
  13. #endif
  14.  
  15. /* This variable is defined in the shared library.  */
  16. int shlibvar1 = 3;
  17.  
  18. /* This variable is defined by another object in the shared library.  */
  19. extern int shlibvar2;
  20.  
  21. /* These functions return the values of the above variables as seen in
  22.    the shared library.  */
  23.  
  24. #ifndef XCOFF_TEST
  25. int
  26. shlib_mainvar ()
  27. {
  28.   return mainvar;
  29. }
  30. #endif
  31.  
  32. #ifndef XCOFF_TEST
  33. int
  34. shlib_overriddenvar ()
  35. {
  36.   return overriddenvar;
  37. }
  38. #endif
  39.  
  40. int
  41. shlib_shlibvar1 ()
  42. {
  43.   return shlibvar1;
  44. }
  45.  
  46. int
  47. shlib_shlibvar2 ()
  48. {
  49.   return shlibvar2;
  50. }
  51.  
  52. /* This function calls a function defined by another object in the
  53.    shared library.  */
  54.  
  55. extern int shlib_shlibcalled ();
  56.  
  57. int
  58. shlib_shlibcall ()
  59. {
  60.   return shlib_shlibcalled ();
  61. }
  62.  
  63. /* This function calls a function defined by the main program.  */
  64.  
  65. #ifndef XCOFF_TEST
  66. extern int main_called ();
  67.  
  68. int
  69. shlib_maincall ()
  70. {
  71.   return main_called ();
  72. }
  73. #endif
  74.  
  75. /* This function is passed a function pointer to shlib_mainvar.  It
  76.    confirms that the pointer compares equally.  */
  77.  
  78. int 
  79. shlib_checkfunptr1 (p)
  80.      int (*p) ();
  81. {
  82.   return p == shlib_shlibvar1;
  83. }
  84.  
  85. /* This function is passed a function pointer to main_called.  It
  86.    confirms that the pointer compares equally.  */
  87.  
  88. #ifndef XCOFF_TEST
  89. int
  90. shlib_checkfunptr2 (p)
  91.      int (*p) ();
  92. {
  93.   return p == main_called;
  94. }
  95. #endif
  96.  
  97. /* This function returns a pointer to shlib_mainvar.  */
  98.  
  99. int
  100. (*shlib_getfunptr1 ()) ()
  101. {
  102.   return shlib_shlibvar1;
  103. }
  104.  
  105. /* This function returns a pointer to main_called.  */
  106.  
  107. #ifndef XCOFF_TEST
  108. int
  109. (*shlib_getfunptr2 ()) ()
  110. {
  111.   return main_called;
  112. }
  113. #endif
  114.  
  115. /* This function makes sure that constant data and local functions
  116.    work.  */
  117.  
  118. #ifndef __STDC__
  119. #define const
  120. #endif
  121.  
  122. static int i = 6;
  123. static const char *str = "Hello, world\n";
  124.  
  125. int
  126. shlib_check ()
  127. {
  128.   const char *s1, *s2;
  129.  
  130.   if (i != 6)
  131.     return 0;
  132.  
  133.   /* To isolate the test, don't rely on any external functions, such
  134.      as strcmp.  */
  135.   s1 = "Hello, world\n";
  136.   s2 = str;
  137.   while (*s1 != '\0')
  138.     if (*s1++ != *s2++)
  139.       return 0;
  140.   if (*s2 != '\0')
  141.     return 0;
  142.  
  143.   if (shlib_shlibvar1 () != 3)
  144.     return 0;
  145.  
  146.   return 1;
  147. }
  148.